/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/26 23:00
  *
  * @file       pd_rtc.h
  * @brief      Header file of Xxx hardware driver.
  *
  * @note       This file contains the Xxx object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/26     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_RTC_H
#define JLC_SKY_RTC_H

#include "stm32f407xx.h"

struct RealTimeClockVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    uint16_t RTC_datetime[7];

    // RealTimeClock virtual table
    struct RealTimeClockVtbl *vptr;
} RealTimeClock;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct RealTimeClockVtbl {
    void (*init)(RealTimeClock *this, uint16_t *RTC_datetime);

    void (*set_datetime)(RealTimeClock *this, uint16_t *RTC_datetime);

    void (*get_datetime)(RealTimeClock *this);

    uint32_t (*get_time)(const RealTimeClock *this);

    uint32_t (*get_date)(const RealTimeClock *this);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void RealTimeClock_constructor(RealTimeClock *this);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void RealTimeClock_init(RealTimeClock *this, uint16_t *RTC_datetime) {
    this->vptr->init(this, RTC_datetime);
}

static inline void RealTimeClock_setDatetime(RealTimeClock *this, uint16_t *RTC_datetime) {
    this->vptr->set_datetime(this, RTC_datetime);
}

static inline void RealTimeClock_getDatetime(RealTimeClock *this) {
    this->vptr->get_datetime(this);
}

static inline uint32_t RealTimeClock_getTime(const RealTimeClock *this) {
    return this->vptr->get_time(this);
}

static inline uint32_t RealTimeClock_getDate(const RealTimeClock *this) {
    return this->vptr->get_date(this);
}

#define YEAR    0
#define MONTH   1
#define DAY     2
#define HOUR    3
#define MINUTE  4
#define SECOND  5
#define WEEK    6

static inline uint16_t RealTimeClock_getYear(const RealTimeClock *this) {
    return this->RTC_datetime[YEAR];
}

static inline uint16_t RealTimeClock_getMonth(const RealTimeClock *this) {
    return this->RTC_datetime[MONTH];
}

static inline uint16_t RealTimeClock_getDay(const RealTimeClock *this) {
    return this->RTC_datetime[DAY];
}

static inline uint16_t RealTimeClock_getHour(const RealTimeClock *this) {
    return this->RTC_datetime[HOUR];
}

static inline uint16_t RealTimeClock_getMinute(const RealTimeClock *this) {
    return this->RTC_datetime[MINUTE];
}

static inline uint16_t RealTimeClock_getSecond(const RealTimeClock *this) {
    return this->RTC_datetime[SECOND];
}

static inline uint16_t RealTimeClock_getWeek(const RealTimeClock *this) {
    return this->RTC_datetime[WEEK];
}
/**
 * @}
 */



#endif //JLC_SKY_RTC_H
